#ifndef LISTVIEW_H
#define LISTVIEW_H

#include "element.h"
#include <QSharedPointer>

class ItemModel;

class QLUISHARED_EXPORT ListView : public Element
{
    Q_OBJECT
public:
    ListView();

    /*********************************************************************
     *                    Copying
     * *******************************************************************/
public:
    virtual bool copyFrom(const Element *e) override;
    virtual Element *clone() const override;

    /*********************************************************************
     *                    Date
     * *******************************************************************/
public:
    Q_PROPERTY(QString head READ head WRITE setHead)

    /**
     * @brief Set ItemModel for ListView, owner is ListView
     * @param model
     */
    void setModel(ItemModel *model);
    ItemModel *model() const;

    template<class T>
    T* model(){
        return qobject_cast<T*>(model());
    }

    void setHead(const QString &head);
    QString head() const;

    Q_INVOKABLE void nextPage();
    Q_INVOKABLE void prevPage();

    int currentRow() const;
    void setCurrentRow(int row);
    int currentPage() const;
    int count() const;
    virtual QRect sizeHint() const override;

protected:
    void setPage(int page);

signals:
    void activated(int row);

private:
    QSharedPointer<ItemModel> model_;
    int current_row_;
    QString head_;


    /*********************************************************************
     *                    paint
     * *******************************************************************/
protected:
    virtual void paintEvent() override;


    /*********************************************************************
     *                    event
     * *******************************************************************/
    Q_PROPERTY(int upKey READ upKey WRITE setUpKey)
    Q_PROPERTY(int downKey READ downKey WRITE setDownKey)

public:
    void setUpKey(int upKey);
    int upKey() const;
    void setDownKey(int downKey);
    int downKey() const;

private:
    int up_key_, down_key_;

public slots:
    void onKeyEvent(int key, int value);


    /*********************************************************************
     *                    MetaInfo
     * *******************************************************************/
public:
    virtual QString getSignalSignature(const QString& name) const override;

};

#endif // LISTVIEW_H
